{% extends '_admin.html' %}
{% import 'public.html' as public %}


{% block main_contain %}
<div class="row" id="LogView">
    <div class="col-lg-12">
        <div class="card card-primary">
            <div class="card-header">
                <div class="col-sm-12 col-md-6">
                    <select v-model="LogFile" class="form-control col-md-4" @change="select_file">
                    {% for f in logs %}
                    <option>{{ f }}</option>
                    {% endfor %}
                    </select>
                </div>
            </div>
            <div class="card-body">
                <div class="row">
                    {% if page_info %}
                    {% for r in page_info %}
                    <span class="col-12 {% if 'ERROR' in r %}text-danger{% endif %}">{{ r }}</span>
                    {% endfor %}
                    {% else %}
                    沒有日志
                    {% endif %}
                </div>
                <div class="row justify-content-center" style="margin-top: 15px;">
                    <ul class="pagination justify-content-center">
                        <li class="page-item"><a class="page-link" href="#">«</a></li>
                        {% for i in pages[:38] %}
                        <li class="page-item {% if i == current_page %}active{% endif %}">
                            <a class="page-link" href="{{ url_for('logs.camera',page=i)}}">{{i}}</a>
                        </li>
                        {% endfor %}
                        <li class="page-item"><a class="page-link" href="#">»</a></li>
                    </ul>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}


{% block scripts %}
{{ super() }}
<script>
    // 日志功能
    var LogView = new Vue({
        el: '#LogView',
        delimiters: ['{[', ']}'],
        data: {
            LogFile: '{{log_file}}'
        },
        methods: {
            // 选择日志文件
            select_file(){
                axios.post("{{ url_for('logs.camera') }}", {SetFilter: this.LogFile})
                .then(response => {
                    if(response.status==200){
                        setTimeout("window.location.reload()")
                    }else{AppMessage.fire({icon: 'error', text: '操作錯誤，請聯係管理員'})}
                })
                .catch(function (error) {alert(error)})
            }
        }
    });
</script>
{% endblock %}


